package mylab.starters.secure.support;

import lombok.Data;
import mylab.starters.secure.enums.HttpMethod;
import mylab.starters.secure.model.Rule;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 鉴权规则注册中心
 * </p>
 */
@Data
public class SecureRuleRegistry {
    private List<Rule> ruleList = new ArrayList<>();
    private List<String> whiteList = new ArrayList<>();

    /**
     * 添加鉴权规则
     *
     * @param path       路径
     * @param method     请求方法
     * @param expression 权限表达式
     * @return 当前对象
     */
    public SecureRuleRegistry addRule(String path, HttpMethod method, String expression) {
        ruleList.add(new Rule(path, method, expression));
        return this;
    }

    /**
     * 添加排除路径
     *
     * @param path 路径
     * @return 当前对象
     */
    public SecureRuleRegistry exclude(String path) {
        whiteList.add(path);
        return this;
    }
}
